package com.stars.home.vmodel

import android.app.Activity
import android.app.Application
import android.content.Intent
import android.os.Bundle
import androidx.databinding.Bindable
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.stars.home.BR
import com.stars.home.activity.*
import com.stars.home.utils.net.NetEngine
import com.tencent.mmkv.MMKV
import com.trailer.base.base.BRepository
import com.trailer.base.base.BViewModel
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch
import kotlinx.coroutines.launch


class AddBankVModel(application: Application) : BViewModel<BRepository>(application) {

    @Bindable
    open var name: String? = null
        set(value) {
            field = value
            notifyPropertyChanged(BR.name)
        }



    @Bindable
    var card: String? = null
        set(value) {
            field = value
            notifyPropertyChanged(BR.card)
        }

    @Bindable
    var bank: String? = null
        set(value) {
            field = value
            notifyPropertyChanged(BR.bank)
        }

    @Bindable
    var bankName: String? = null
        set(value) {
            field = value
            notifyPropertyChanged(BR.bankName)
        }


    fun toSubmit(){
        if(name.isNullOrEmpty()){

            toast("请输入真实姓名")
            return
        }
        if(card.isNullOrEmpty()){

            toast("请输入身份证号")
            return
        }
        if(bank.isNullOrEmpty()){

            toast("请输入银行卡号")
            return
        }
        if(bankName.isNullOrEmpty()){

            toast("请输入开户银行")
            return
        }


        viewModelScope.launch {
            var it=repository().lreq { NetEngine.service.backAdd(name,card,bank,bankName) }
            if(it.ok(true)){

                val intent = Intent()
                var con=repository().context as Activity
                con.setResult(Activity.RESULT_OK, intent)
                con.finish()


            }
        }
    }

}



